// pages/account/setting.js
var app = getApp();
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.emit('acceptDataFromOpenedPage', { data: "id" });
    eventChannel.emit('someEvent', { data: "id" });
    // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
    eventChannel.on('acceptDataFromOpenerPage', function (data) {
      console.log(data, "data")
      that.setData({
        columnId: data
      })
      that.getList()
    })
  },
  // 分享
  onShareAppMessage: function (res) {
    var that = this;
    return {
      title: '贷投狗小程序',
      path: 'pages/account/setting',
      success: function (res) {
        that.shareClick();
      },
      fail: function (res) {
      }
    }
  },
  getList: function () {
    let that = this
    let columnId = this.data.columnId
    util.https(app.globalData.api + "/applet/project/findOne/" + columnId, "GET", {},
      function (data) {
        if (data.code == 200) {
          data.data.yearRate = util.formatDecimal(data.data.yearRate, 2)
          data.data.brokerExtract = data.data.brokerExtract.substring(3)
          that.setData({
            columnData: data.data,
            moveSpecialCode: data.data.moveSpecialCode
          })
        } else {
          util.toolTip(that, data.message)
        }
      }
    )
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})